package com.clerkq.Scroller
{
	
	import com.content.model.LoadedAssets.SkinProxy;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	
	import gs.TweenLite;
	
    public class Arrows extends UIObject implements IDisposable {

        private var _id:int;		// 0为 top/left, 1为 bottom/right
        private var _arrow:Sprite;
        
        private var _direction:String = ScrollerType.VERTICAL;
		
		public static const WIDTH:Number = 15;
		public static const HEIGHT:Number = 15;
        public static const ON_RELEASE_ARROW:String = "onReleaseArrow";
        public static const ON_PRESS_ARROW:String = "onPressArrow";

        public function Arrows(id:int, direction:String){
            _id = id;
            _direction = direction;
            create();
        }
        private function create():void{
			mouseChildren = false;
            buttonMode = true;
            //_arrow = new AssetManager.TScrollerArrow() as Sprite;
			
            _arrow = new SkinProxy.IMG_SArrowButton as Sprite;
   
            if(_direction == ScrollerType.VERTICAL){
            	if (_id == 0){
	            }else{
	            	_arrow.y = _arrow.height;
					_arrow.scaleY = -1;
	            }
            }else{
            	if (_id == 0){
            		_arrow.rotation = -90;
					_arrow.y = _arrow.width;
	            }else{
	            	_arrow.rotation = 90;
					_arrow.x = _arrow.height;
	            }
            }
            addChild(_arrow);
            
            this.addEventListener(MouseEvent.MOUSE_OVER, BtnOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, BtnOut);
			this.addEventListener(MouseEvent.MOUSE_DOWN, BtnPress);
			this.addEventListener(MouseEvent.MOUSE_UP, BtnRelease);
        }
        /*public function setColorTween(color:uint):void{
			TweenLite.to(_arrow, 0.2, {_color:color});

//            var colTran:ColorTransform = new ColorTransform();
//            colTran.color = color;
//            obj.transform.colorTransform = colTran; 

        }*/
        
        public function drawTriangle(long:Number, color:uint, alpha:Number):Sprite{
        	var triangle:Sprite = new Sprite();
        	//triangle.graphics.lineStyle(1.0, 0x000000, 0.80);
        	triangle.graphics.beginFill(color, alpha);
        	// 输入两边一角画三角形
            var long:Number = long;
            var point1:Point = new Point();
            point1.x = -long/2;
            point1.y = Math.tan(30/180*Math.PI) * long/2;
            
            var point2:Point = new Point();
            point2.x = 0;
            point2.y = -point1.y*2;
            
            var point3:Point = new Point();
            point3.x = long/2;
            point3.y = point1.y;
            
            
			var a:Number = 10;
			var b:Number = 10;
			var ag:Number = 60;
			//triangle.graphics.lineStyle(0, 0x000000, 1.0)
			triangle.graphics.moveTo(point1.x,point1.y);
			triangle.graphics.lineTo(point2.x,point2.y);
			triangle.graphics.lineTo(point3.x,point3.y);
			triangle.graphics.lineTo(point1.x,point1.y);
			
			return triangle;
        }
        
        // Events
        private function BtnRelease(evt:MouseEvent):void{
            this.dispatchEvent(new Event(ON_RELEASE_ARROW, false, false));
        }
		private function BtnOver(evt:MouseEvent):void{
            //setColorTween(0xff0000);
        }
		private function BtnOut(evt:MouseEvent):void{
            //setColorTween(0xff0000);
        }
		private function BtnPress(evt:MouseEvent):void{
        	evt.stopImmediatePropagation();
            this.dispatchEvent(new Event(ON_PRESS_ARROW, false, false));
        }
		
		public function Dispose():void{
			this.removeEventListener(MouseEvent.MOUSE_OVER, BtnOver);
			this.removeEventListener(MouseEvent.MOUSE_OUT, BtnOut);
			this.removeEventListener(MouseEvent.MOUSE_DOWN, BtnPress);
			this.removeEventListener(MouseEvent.MOUSE_UP, BtnRelease);
		}
		// Get and Set
        public function get id():Number{            return _id;        }
    }
}